import 'package:flutter/material.dart';
import 'package:flutter_fitness/model/db/DBHelper.dart';

final String tableRecord = "record";
final String columnUserId = "userId";
final String columnWeight = "weight";
final String columnIsRead = "isRead";
final String columnStep = "step";
final String columnIsPray = "isPray";
final String columnYear = "year";
final String columnMonth = "month";
final String columnDay = "day";

class Record {
  int id; // 自增长id
  int userId; // 归于那个用户
  double weight; // 体重
  bool isRead; // 是否读经
  int step; // 步数
  bool isPray; // 是否祷告
  int year; // 年
  int month; // 月
  int day; // 日

  Record({
    @required this.userId,
    this.weight = -1,
    this.isRead = false,
    this.step = 0,
    this.isPray = false,
    @required this.year,
    @required this.month,
    @required this.day,
  });

  Record.fromMap(Map<String, Object> map) {
    id = map[columnId];
    userId = map[columnUserId];
    weight = map[columnWeight];
    isRead = map[columnIsRead] == 1;
    step = map[columnStep];
    isPray = map[columnIsPray] == 1;
    year = map[columnYear];
    month = map[columnMonth];
    day = map[columnDay];
  }

  Map<String, Object> toMap() {
    final map = <String, Object>{
      columnUserId: userId,
      columnWeight: weight,
      columnIsRead: isRead ? 1 : 0,
      columnStep: step,
      columnIsPray: isPray ? 1 : 0,
      columnYear: year,
      columnMonth: month,
      columnDay: day,
    };
    if (id != null) map[columnId] = id;
    return map;
  }
}
